// 通过 webpack-merge 插件 合并配置文件
const merge = require('webpack-merge');
//获取 webpack.common.js 文件
const common = require('./webpack.prod.common.js');
//在 node.js下获取 获取路径
const path = require('path');
//引用本地 webpack 功能
const webpack = require('webpack');
//引用clean-webpack-plugin 打包前先清除dist文件夹
const CleanWebpackPlugin = require('clean-webpack-plugin');
//引用extract-text-webpack-plugin 把 CSS 分离成文件
const ExtractTextPlugin = require('extract-text-webpack-plugin');

//配置需要合并的文件
const connectJs = require('./mergeConfig.json');

module.exports = merge(common, {
  entry: {
    AngularJs: connectJs.mergeJs,
    main: './frameworkCode/jsDependencies.js'
  },
  output: {
    path: path.resolve(__dirname, 'dist/source'),
    //[name]对应的是 entry中的"app.bundle"
    filename: 'js/[name].js'
  },
  module: {
    rules: [
      //配置 sass 加载器
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: [
            {
              // loader: ['css-loader?sourceMap', 'sass-loader?sourceMap'],
              loader: 'css-loader?sourceMap',
              options: {
                minimize: false //css压缩
              }
            },
            {
              // loader: ['css-loader?sourceMap', 'sass-loader?sourceMap'],
              loader: 'sass-loader?sourceMap',
              options: {
                minimize: false //css压缩
              }
            }
          ]
        })
      }
    ]
  },
  plugins: [
    //清空打包文件夹
    new CleanWebpackPlugin(['dist/source']),
    //重构CSS文件
    new ExtractTextPlugin({
      filename: 'css/index.css' //路径以及命名
    })
  ],
  devtool: 'source-map'
});
